clc
clear

T =1;
t = linspace(0,pi,10000);
x=1/2*square(2*pi*t/T);
figure (1)
plot(t,x,'r')
grid on 
hold on

k=1:2:41;
fourier_x=0;

for i =1:1:20
    fourier_x=fourier_x+2/(k(i)*pi)*sin(2*pi*k(i)*t/T);
end

plot(t,fourier_x,'b')

R=1;
C=1;
w_0=1/(R*C);
H_1p_p = 1./(1+1i*k*R*C/T);
r_p = abs(H_1p_p);
theta_p = angle(H_1p_p);

fourier_x_lp=0;

for i =1:1:20
    fourier_x_lp = fourier_x_lp+2*r_p(i)/(k(i)*pi)*sin(2*pi*k(i)/T*t+theta_p(i));
end

figure(2);
plot(t,x,'r');grid on;hold on;
plot(t,fourier_x_lp,'b')


